<template>
	<uv-modal ref="orderConfirm" title="完工审核" confirmColor="#0BCA89" :asyncClose="true" :showCancelButton="false"
		confirmText="确定" @confirm="confirm" @close="closed">
		<view class="w-100 solid-top">
			<uv-form labelPosition="top" labelWidth="220" :model="formData" :rules="rules" ref="authForm">
				<uv-form-item label="实际面积" prop="actualArea" labelPosition="left" borderBottom>
					<view class="">
						{{record.actualArea}} 亩
					</view>
				</uv-form-item>
				<uv-form-item label="实际金额" prop="actualMoney" labelPosition="left" borderBottom>
					<view class="flex-sub text-black color-red">
						<text class="text-sm">￥</text>
						<text class="text-lg text-bold">{{record.actualMoney || ''}}</text>
					</view>
				</uv-form-item>
				<uv-form-item label="审核结果" prop="status" borderBottom>
					<uv-radio-group v-model="formData.status" placement="row">
						<uv-radio :customStyle="{margin: '10px'}" name="6" activeColor="#0BCA89" label="同意"></uv-radio>
						<uv-radio name="10" activeColor="#0BCA89" label="不同意"></uv-radio>
					</uv-radio-group>
				</uv-form-item>
				<uv-form-item label="审核意见" prop="auditReason" v-if="formData.status==10">
					<uv-textarea :maxlength="-1" autoHeight v-model="formData.auditReason">
					</uv-textarea>
				</uv-form-item>
			</uv-form>
		</view>

	</uv-modal>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				orderLogId: '',
				record: {},
				formData: {
					status: '',
					auditReason: ''
				},
				rules: {
					'auditReason': {
						type: 'string',
						required: true,
						message: '请填写审核意见',
						trigger: ['blur', 'change']
					},
					'status': {
						required: true,
						message: '请选择审核结果',
						trigger: ['blur', 'change']
					},
				},
			}
		},
		methods: {
			show(data) {
				this.record = data
				this.$refs.orderConfirm.open();
				this.formData.status = ''
				this.formData.auditReason = ''
				this.$nextTick(() => {
					this.$refs.authForm.resetFields();
					this.$refs.authForm.clearValidate();
				})
			},
			confirm() {
				this.$refs.authForm.validate().then(res => {
					this.$http.post('/cadre/assignOrder/allocation', {
						...this.record,
						...this.formData
					}).then(res => {
						if (res.code == 200) {
							// this.$emit('success')
							this.$refs.orderConfirm.close();
							// 同意了调起支付
							if(this.formData.status == 6) {
								this.$store.dispatch('payment/payAction', this.record).then(res => {
									console.log('支付成功回调', res)
									this.$emit('success')
								}).catch(err => {
									console.log('支付失败回调', err)
									this.$emit('success')
								})
							}
							this.$emit('success')
							// uni.$uv.route({
							// 	url: '/subPages/pages/orderPay/index',
							// 	params: {
							// 		id: this.record.id,
							// 		orderLogId: this.record.orderLogId,
							// 	}
							// })
						} else {
							uni.showToast({
							// icon: 'error',
							title: res.msg
							})
							this.$refs.orderConfirm.closeLoading()
						}
					})
				}).catch(errors => {
					this.$refs.orderConfirm.closeLoading()
					uni.showToast({
						icon: 'error',
						title: '校验失败'
					})
				})

			},
			closed() {
				this.$refs.orderConfirm.closeLoading()
			}
		}
	}
</script>

<style>
</style>